home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / usr / lib / linux-boot-probes / 50mounted-tests
Encoding:
Text File  |  2007-01-11  |  3.1 KB  |  122 lines

  1. #!/bin/sh
  2. # Sub-tests that require a mounted partition.
  3. . /usr/share/os-prober/common.sh
  4. set -e
  5.  
  6. partition=$1
  7.  
  8. parsefstab () {
  9.     while read line; do
  10.         case "$line" in
  11.             "#"*)
  12.                 :    
  13.             ;;
  14.             *)
  15.                 set -- $line
  16.                 echo $1 $2 $3
  17.             ;;
  18.         esac
  19.     done
  20. }
  21.  
  22. tmpmnt=/var/lib/os-prober/mount
  23. if [ ! -d $tmpmnt ]; then
  24.     mkdir $tmpmnt
  25. fi
  26.  
  27. # If DO_MOUNTED is set, also process already mounted partitions by temporarily
  28. # unmounting them.
  29. oldmnt=$(mount |grep "$partition "|cut -d' ' -f 3)
  30. if [ -n "$DO_MOUNTED" ] && [ -n "$oldmnt" ]; then
  31.     oldopts=$(mount |grep "$partition "|sed 's/.*(\(.*\)).*/\1/')
  32.     umount $partition
  33. fi
  34.  
  35. for type in $(grep -v nodev /proc/filesystems); do
  36.     if mount -o ro -t $type $partition $tmpmnt 2>/dev/null; then
  37.         bootpart=""
  38.         if [ -e "$tmpmnt/etc/fstab" ]; then
  39.             # Try to mount any /boot partition.
  40.             bootmnt=$(parsefstab < $tmpmnt/etc/fstab | grep " /boot ") || true
  41.             if [ -n "$bootmnt" ]; then
  42.                 set -- $bootmnt
  43.                 boottomnt=""
  44.                 mounted=""
  45.                 if [ -e "$1" ]; then
  46.                     bootpart="$1"
  47.                     boottomnt="$1"
  48.                 elif [ -e "$tmpmnt/$1" ]; then
  49.                     bootpart="$1"
  50.                     boottomnt="$tmpmnt/$1"
  51.                 elif [ -e "/target/$1" ]; then
  52.                     bootpart="$1"
  53.                     boottomnt="/target/$1"
  54.                 elif echo "$1" | grep -q "LABEL="; then
  55.                     debug "mounting boot partition by label for linux system on $partition: $1"
  56.                     label=$(echo "$1" | cut -d = -f 2)
  57.                     if /target/bin/mount -L "$label" -o ro $tmpmnt/boot -t "$3"; then
  58.                         mounted=1
  59.                         bootpart=$(mount | grep $tmpmnt/boot | cut -d " " -f 1)
  60.                     else
  61.                         error "failed to mount by label"
  62.                     fi
  63.                 elif echo "$1" | grep -q "UUID="; then
  64.                     debug "mounting boot partition by UUID for linux system on $partition: $1"
  65.                     uuid=$(echo "$1" | cut -d = -f 2)
  66.                     if /target/bin/mount -U "$uuid" -o ro $tmpmnt/boot -t "$3"; then
  67.                         mounted=1
  68.                         bootpart=$(mount | grep $tmpmnt/boot | cut -d " " -f 1)
  69.                     else
  70.                         error "failed to mount by UUID"
  71.                     fi
  72.                 else
  73.                     bootpart=""
  74.                 fi
  75.  
  76.                 if [ ! "$mounted" ]; then
  77.                     if [ -z "$bootpart" ]; then
  78.                         debug "found boot partition $1 for linux system on $partition, but cannot map to existing device"
  79.                     else
  80.                         debug "found boot partition $bootpart for linux system on $partition"
  81.                         if ! mount -o ro "$boottomnt" $tmpmnt/boot -t "$3"; then
  82.                             error "failed to mount $boottomnt on $tmpmnt/boot"
  83.                         fi
  84.                     fi
  85.                 fi
  86.             fi
  87.         fi
  88.         if [ -z "$bootpart" ]; then
  89.             bootpart="$partition"
  90.         fi
  91.         
  92.         for test in /usr/lib/linux-boot-probes/mounted/*; do
  93.             if [ -f $test ] && [ -x $test ]; then
  94.                 debug "running $test $partition $bootpart $tmpmnt $type"
  95.                 if $test $partition $bootpart $tmpmnt $type; then
  96.                     debug "$test succeeded"
  97.                     umount $tmpmnt/boot 2>/dev/null || true     
  98.                     umount $tmpmnt
  99.                     if [ -n "$DO_MOUNTED" ] && [ -n "$oldmnt" ]; then
  100.                         mount $partition $oldmnt -o $oldopts
  101.                     fi
  102.                     rmdir $tmpmnt || true
  103.                     exit 0
  104.                 fi
  105.             fi
  106.         done
  107.         
  108.         umount $tmpmnt/boot 2>/dev/null || true     
  109.         umount $tmpmnt
  110.         if [ -n "$DO_MOUNTED" ] && [ -n "$oldmnt" ]; then
  111.             mount $partition $oldmnt -o $oldopts
  112.         fi
  113.  
  114.         break
  115.     fi
  116. done
  117.  
  118. rmdir $tmpmnt || true
  119.  
  120. # No tests found anything.
  121. exit 1
  122.